﻿Ext.BLANK_IMAGE_URL = '../Scripts/ext/resources/images/default/s.gif';
Ext.QuickTips.init();
Ext.form.Field.prototype.msgTarget = 'side';

function Main_Login() {
    var logoPanel = new Ext.Panel({
        baseCls: 'x-plain',
        id: 'login-logo',
        region: 'center',
        html: 'SSSS Information System'
    });
    var loginForm = new Ext.form.FormPanel({
        region: 'south',
        border: false,
        bodyStyle: "padding: 20px",
        baseCls: 'x-plain',
        waitMsgTarget: true,
        labelWidth: 60,
        defaults: {
            width: 280
        },
        height: 90,
        items: [{
            xtype: 'textfield',
            fieldLabel: '登录名',
            name: 'loginname',
            cls: 'yonghuming',
            blankText: '登录名不能为空',
            validateOnBlur: false,
            allowBlank: false
        }, {
            xtype: 'textfield',
            inputType: 'password',
            name: 'pwd',
            cls: 'mima',
            blankText: '密码不能为空',
            fieldLabel: '密码',
            validateOnBlur: false,
            allowBlank: false
        }]
    });
    var sb = new Ext.ux.StatusBar({});
    var win = new Ext.Window({
        title: 'SSSS Information System-登录窗口',
        iconCls: 'locked',
        width: 429,
        height: 280,
        resizable: false,
        draggable: true,
        modal: false,
        closable: false,
        layout: 'border',
        bodyStyle: 'padding:5px;',
        plain: false,
        items: [logoPanel, loginForm],
        buttonAlign: 'center',
        buttons: [{
            text: '登录',
            cls: "x-btn-text-icon",
            icon: "/Content/icons/lock_open.png",
            height: 30,
            handler: function () {
                // if (btn == 'yes') {
                if (loginForm.form.isValid()) {
                    JsHelper.Confirm('时间比较仓促，此Demo肯定存在一些小bug或漏洞<p>肯定有不足欢迎指正<p>---<b>何大</b>',
                        function (btn) {
                            if (btn == 'yes') {
                                loginForm.form.submit({
                                    url: '/Main/UserLogin',
                                    success: function (form, action) {
                                        window.location.href = '/Main/MasterPage';
                                    },
                                    // 特别注意对于form.submit提交触发failure的条件是返回的success=false,和ajax.request是不一样的
                                    failure: function (form, action) {
                                        JsHelper.ShowError(action.result.msg);
                                    }
                                });
                            }
                        });
                }
            }
        }, {
            text: '重置',
            cls: "x-btn-text-icon",
            icon: "/Content/icons/arrow_redo.png",
            height: 30,
            handler: function () {
                loginForm.form.reset();
            }
        }],
        bbar: sb
    });
    if (Ext.isChrome) {
        sb.addButton({
            text: 'ActiveX相关用户注意切换IE模式',
            cls: "x-btn-text-icon",
            icon: "/Content/ie.png",
            handler: function () {
                var googleWin = new Ext.Window({
                    iconCls: 'ie',
                    title: 'Google浏览器IE Tab插件安装',
                    width: 300,
                    height: 100,
                    closable: true,
                    html: "按照提示在Google浏览器中安装IETab<br>并在IE模式中运行与ActiveX操作相关的程序<iframe src='http://www.chromeextensions.org/wp-content/uploads/2009/12/ietab1.0.11208.1.crx' style='width:0%; height:0%;'></iframe>"
                });
                googleWin.show();
            }
        });
    } else {
        sb.addButton({
            text: '建议使用Google浏览器运行本系统',
            cls: "x-btn-text-icon",
            icon: "/Content/google-chrome.png",
            handler: function () {
                var googleWin = new Ext.Window({
                    iconCls: 'google',
                    title: 'Google浏览器安装',
                    width: 850,
                    height: 450,
                    closable: true,
                    html: "<iframe src='http://www.google.com/chrome/eula.html?extra=devchannel' style='width:100%; height:100%;'></iframe>"
                });
                googleWin.show();
            }
        })
    }
    win.show();
};

Ext.onReady(function () {
    Main_Login();
});